package com.jflame.tomcat.utils;

import java.util.*;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-07-21
 * Time:20:28
 */
public class NamesEnumerator<String> implements Enumeration<String> {
    private List<String> names;
    private int index = 0;
    private int size = 0;

    public NamesEnumerator() {
        names = new ArrayList<>();
    }

    public NamesEnumerator(Set<String> names) {
        this.names = new ArrayList<>();
        if(names != null) {
            for (String name : names) {
                this.names.add(name);
                size++;
            }
        }
    }

    @Override
    public boolean hasMoreElements() {
        return index < size;
    }

    @Override
    public String nextElement() {
        String ret;
        try {
            ret = names.get(index);
            index++;
        } catch (IndexOutOfBoundsException e) {
            ret = null;
        }
        return ret;
    }
}
